Item = function(data) {	
	function getAttribute(name) {
		var x = 0;
		var keys = {
			'str' : 'Strength_Item',
			'dex' : 'Dexterity_Item',
			'int' : 'Intelligence_Item',
			'vit' : 'Vitality_Item',
			'aspd': 'Attacks_Per_Second_Percent',
			'crit': 'Crit_Percent_Bonus_Capped',
			'chd' : 'Crit_Damage_Percent'
		};
				
		if(data.attributesRaw[keys[name]])				
			x += data.attributesRaw[keys[name]].max;									
		
		for(var i=0,l=data.gems.length;i<l;i++)
		{
			if(data.gems[i].attributesRaw[keys[name]])
				x += data.gems[i].attributesRaw[keys[name]].max;
		}	
		return x;
	}
	
	function getDamage(name) {
		var keys = { 
			'min' : 'Min',
			'max' : 'Delta'
		};
		
		var x = 0;		
		var physical = 0;
		
		//weapon percent bonus damage
		var percentBonus = 1;
		if(data.attributesRaw['Damage_Weapon_Percent_Bonus#Physical'])
			percentBonus += data.attributesRaw['Damage_Weapon_Percent_Bonus#Physical'].max
		
		//weapon physical damage
		if(data.attributesRaw['Damage_Weapon_' + keys[name] + '#Physical'])
			x += data.attributesRaw['Damage_Weapon_' + keys[name] + '#Physical'].max;
		
		//weapon bonus damage
		if(data.attributesRaw['Damage_Weapon_Bonus_' + keys[name] + '#Physical'])
			x += data.attributesRaw['Damage_Weapon_Bonus_' + keys[name] + '#Physical'].max;		

		//other item damage	
		if(data.attributesRaw['Damage_' + keys[name] + '#Physical'])
			x += data.attributesRaw['Damage_' + keys[name] + '#Physical'].max;	

		//other item bonus damage
		if(data.attributesRaw['Damage_Bonus_' + keys[name] + '#Physical'])
			x += data.attributesRaw['Damage_Bonus_' + keys[name] + '#Physical'].max;			
			
		physical = x;

		//weapon arcane damage
		if(data.attributesRaw['Damage_Weapon_' + keys[name] + '#Arcane'])
			x += data.attributesRaw['Damage_Weapon_' + keys[name] + '#Arcane'].max;	

		//weapon holy damage
		if(data.attributesRaw['Damage_Weapon_' + keys[name] + '#Holy'])
			x += data.attributesRaw['Damage_Weapon_' + keys[name] + '#Holy'].max;				
			
		//weapon fire damage
		if(data.attributesRaw['Damage_Weapon_' + keys[name] + '#Fire'])
			x += data.attributesRaw['Damage_Weapon_' + keys[name] + '#Fire'].max;	

		//weapon poison damage
		if(data.attributesRaw['Damage_Weapon_' + keys[name] + '#Poison'])
			x += data.attributesRaw['Damage_Weapon_' + keys[name] + '#Poison'].max;	

		//weapon lightning damage
		if(data.attributesRaw['Damage_Weapon_' + keys[name] + '#Lightning'])
			x += data.attributesRaw['Damage_Weapon_' + keys[name] + '#Lightning'].max;					
	
	
		if(name == 'min')
		{
			return (physical * percentBonus) + x - physical;			
		}
		else
		{
			var min = 0;

			if(data.attributesRaw['Damage_Weapon_Bonus_Min#Physical'])
				min += data.attributesRaw['Damage_Weapon_Bonus_Min#Physical'].max;	
			
			if(data.attributesRaw['Damage_Bonus_Min#Physical'])
				min += data.attributesRaw['Damage_Bonus_Min#Physical'].max;	
			
			return (physical - min) * percentBonus + x - physical; 				
		}
	}
	
	function getAttackSpeed() {
		if(data.attacksPerSecond)
			return data.attacksPerSecond.max;
		else
			return 0;
	}
	//offhand types: Orb, Quiver, Shield, Mojo
	function isWeapon() {
		return data.type.id != 'Orb' && data.type.id != 'Quiver' && data.type.id != 'Shield' && data.type.id != 'Mojo';
	}
	
	function getIconUrl() {
		return 'http://us.media.blizzard.com/d3/icons/items/large/' + data.icon + '.png';
	}
	
	function getIconColor() {
		if(data.displayColor == 'orange')
			return '#D96500'
		
		if(data.displayColor == 'green')
			return '#87A73D';
			
		if(data.displayColor == 'yellow')
			return '#B1A73C';
	}	
	
	function done() {
		return true;
	}
	
	var obj = {
		data : data ,
		getAttribute : getAttribute,
		getDamage : getDamage,
		getAttackSpeed : getAttackSpeed,
		getIconUrl : getIconUrl,
		getIconColor : getIconColor,
		isWeapon : isWeapon,
		done : done
	};
	
	return obj;
}
